<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let loginList = [
        { userName: 'admin', password: 'admin321' },
        { userName: 'zhangsan', password: 'zs321' },
        { userName: 'lisi', password: 'ls321' },
        { userName: 'yyqx', password: 'yyqx321' },
      ]
      let userInfo = {
        token1: {
          city: '杭州',
          money: '1000w',
          sex: '女',
          userName: 'admin',
          password: 'admin321',
        },
        token2: {
          city: '北京',
          money: '1100w',
          sex: '女',
          userName: 'zhangsan',
          password: 'zs321',
        },
        token3: {
          city: '北京',
          money: '800w',
          sex: '男',
          userName: 'lisi',
          password: 'ls321',
        },
        token4: {
          city: '天津',
          money: '600w',
          sex: '男',
          userName: 'yyqx',
          password: 'yyqx321',
        },
      }

      function getUser() {
        
          let loginName = prompt(`请输入账号`)
          let loginPwd = prompt(`请输入密码`)
          let tokennum = 'token'+Math.floor(Math.random()*4+1)
         
          for (let i = 0 ; i<loginList.length; i++) {
            if (
              loginName === loginList[i].userName &&
              loginPwd === loginList[i].password
            ) {
              alert(`登录成功,用户具体信息：
          city:${userInfo[tokennum].city}
          money:${userInfo[tokennum].money}
          sex:${userInfo[tokennum].sex}
          userName:${loginName}`)

              return true
            } 
           
          } return false
          // let last = getUser()
        // while (!last) {
        //    alert(`你没机会了`)
        //    break
        // }
      }
      let flag = getUser()
      while (!flag) {
        let choose = +prompt(`账号不存在
                1.注册
                2.直接退出`)
        switch (choose) {
          case 1:
            userName = prompt(`请输入用户名`)
            password = prompt(`请输入密码`)
            alert(`你已注册成功，请登录`)
            loginList.push({ userName, password })
           
            flag = true
            let end = getUser()
                    // 登录失败 给个提示 直接退出
                    if (!end) {
                        alert('再次输错，已无机会，直接退出了')
                    }
            break
          case 2:
            flag = true
            break
          default:
            alert(`请输入正确的指令`)
            break
        }
      }
     
   
    </script>
  </body>
</html>
